import React from "react";
import {
  Image,
  ImageSourcePropType,
  StyleProp,
  StyleSheet,
  View,
  ViewStyle,
} from "react-native";

interface AvatarProps {
  /**
   * The image source for the avatar.
   */
  image: ImageSourcePropType;
  /**
   * The size of the avatar in pixels.
   * Default is 64.
   */
  size?: number;
  /**
   * Custom styles for the avatar container.
   */
  style?: StyleProp<ViewStyle>;
}

const defaultSize = 64;

/**
 * A simple Avatar component to display a circular image.
 *
 * ## Usage
 * ```js
 * import Avatar from './Avatar';
 *
 * const MyComponent = () => (
 * <Avatar
 * size={50}
 * image={require('./assets/avatar.png')}
 * />
 * );
 * ```
 */
const AvatarImage = ({ image, size = defaultSize, style }: AvatarProps) => {
  const avatarSize = {
    width: size,
    height: size,
    borderRadius: size / 2,
  };

  return (
    <View style={[styles.container, avatarSize, style]}>
      <Image source={image} style={avatarSize} />
    </View>
  );
};

const styles = StyleSheet.create({
  container: {
    overflow: "hidden",
  },
});

export default AvatarImage;
